<?php

$problem = $submission->problem;
$time_limit = $problem->get_config('time_limit');
$memory_limit = $problem->get_config('memory_limit');
$testcases = $problem->get_config('testcases');

//Compile
$source_content = $submission->get_submit_content('source_content');
$source_lang = $submission->get_submit_content('source_lang');
$source_path = Sandbox::get_temp_name();
file_put_contents($source_path, $source_content);
try
{
    $execpath = Compiler::compile($source_path, $source_lang);
}
catch (CompilerException $ex)
{
    $submission->set_grade_content("verdict", "Compile Error");
    return;
}
unlink($source_path);
//Execute
$verdict = "";
$isruntimeok = true;
$istimelimit = false;

foreach($testcases as $testcase)
{
    $inputpath = $problem->get_evaluator_file($testcase['input']);
    $outputpath = $problem->get_evaluator_file($testcase['output']);
    $tmpoutput = Sandbox::get_temp_name();
    $sandboxparam = "-e -w $time_limit -m $memory_limit -i $inputpath -o $tmpoutput";
    $execoutput = "";
    Sandbox::execute($sandboxparam, $execpath, &$execoutput);
    unlink($tmpoutput);
}

unlink($execpath);